<template>
    <div class="home-layout">
        <div class="home-main">
            <header class="header">
                <div></div>
                <img src="/src/assets/logo.png" alt="logo" width="150" @click="goHome">
                <div class="pc-header-extra">
                    <div class="dropdown pc-header-extra-item">
                        <div class="dropdown-title"><span>Categories</span></div>
                        <div class="dropdown-list">
                            <p class="dropdown-list-item" @click="goArticle(item)" v-for="(item, index) in category"
                                :key="index">{{ item?.alias }}</p>
                        </div>
                    </div><span class="pc-feedback" @click="showFeedBack"><span
                            class="pc-feedback-text">Feedback</span></span>
                </div>
            </header>
            <main class="main">
                <div class="home-page">
                    <div class="search-bar-wrap search-bar-dark ">
                        <div class="adm-input search-bar-input"><input class="adm-input-element" v-model="searchText"
                                placeholder="Enter your keywords" @keyup.enter="handleSearch"></div><span
                            @click="handleSearch" class="search-icon"></span>
                    </div>
                    <template v-for="(item, index) in data" :key="index">
                        <div class="trending-module home-page-module"
                            v-if="item.articleList?.length < 4 || item.articleList?.length >= 6">
                            <h3 class="home-page-module-title">{{ item.title }}</h3>
                            <div class="trend-list">
                                <div class="trend-list-item" v-for="(aitem, aindex) in item?.articleList" :key="aindex">
                                    <div class="vertical-news-card news-card news-card-dark trending-article-card">
                                        <div class="news-card-top "><a :href="`/detail/${aitem?.id}`"
                                                class="news-card-img-link"><img :src="aitem?.image"
                                                    alt="news image"></a></div>
                                        <div class="news-card-bottom">
                                            <p class="news-card-cnt"><a :href="`/detail/${aitem.id}`"
                                                    :title="aitem?.title" class="ellipsis-2">{{ aitem?.title }}</a></p>
                                        </div>
                                    </div>
                                </div>

                            </div>
                        </div>
                        <div class="recent-publish-module home-page-module" v-if="item.articleList?.length === 5">
                            <h3 class="home-page-module-title">{{ item.title }}</h3>
                            <div class="recent-publish-module-list">
                                <div class="recent-publish-module-list-item recent-publish-module-list-item-large">
                                    <div class="vertical-news-card news-card news-card-dark ">
                                        <div class="news-card-top recent-publish-module-list-item-img-large"><a
                                                :href="`/detail/${item.articleList?.[0]?.id}`"
                                                class="news-card-img-link"><img :src="item.articleList?.[0]?.image"
                                                    style="height: auto;" alt="news image"></a>
                                        </div>
                                        <div class="news-card-bottom">
                                            <p class="news-card-cnt"><a :href="`/detail/${item.articleList?.[0]?.id}`"
                                                    :title="item.articleList?.[0]?.title" class="ellipsis-2">{{
                                                        item.articleList?.[0]?.title }}</a>
                                            </p>
                                        </div>
                                    </div>
                                </div>
                                <div class="recent-publish-module-list-right">
                                    <div class="recent-publish-module-list-item"
                                        v-for="(aitem, aindex) in item?.articleList?.filter((_item, _index) => _index != 0)"
                                        :key="aindex">
                                        <div class="vertical-news-card news-card news-card-dark ">
                                            <div class="news-card-top recent-publish-module-list-item-img"><a
                                                    :href="`/detail/${aitem?.id}`" class="news-card-img-link"><img
                                                        :src="aitem?.image" alt="news image"></a></div>
                                            <div class="news-card-bottom">
                                                <p class="news-card-cnt"><a :href="`/detail/${aitem?.id}`"
                                                        :title="aitem.articleList?.[0]?.title" class="ellipsis-2">{{
                                                            aitem?.title
                                                        }}</a></p>
                                            </div>
                                        </div>
                                    </div>

                                </div>
                            </div>
                        </div>
                        <div class="all-article-module home-page-module" v-if="item.articleList?.length === 4">
                            <h3 class="home-page-module-title">{{ item?.title }}</h3>
                            <div class="all-article-module-list">
                                <div class="all-article-module-list-item all-article-module-list-item-large">
                                    <div class="vertical-news-card news-card news-card-dark ">
                                        <div class="news-card-top all-article-module-list-item-img-large"><a
                                                :href="`/detail/${item?.articleList?.[0]?.id}`"
                                                class="news-card-img-link"><img :src="item?.articleList?.[0]?.image"
                                                    style="height: auto;" alt="news image"></a>
                                        </div>
                                        <div class="news-card-bottom">
                                            <p class="news-card-cnt"><a :href="`/detail/${item?.articleList?.[0]?.id}`"
                                                    title="New BMW 3 Series" class="ellipsis-2">{{ item?.title }}</a>
                                            </p>
                                        </div>
                                    </div>
                                </div>
                                <div class="all-article-module-list-right">
                                    <div class="all-article-module-list-item-right"
                                        v-for="(aitem, aindex) in item?.articleList?.filter((_item, _index) => _index != 0)"
                                        :key="index">
                                        <div class="horizontal-news-card news-card news-card-dark ">
                                            <div class="news-card-left all-article-module-list-item-img"><a
                                                    :href="`/detail/${item}`"><img :src="aitem?.image"
                                                        alt="article image" class="news-card-img-link"></a></div>
                                            <div class="news-card-right">
                                                <p class="news-card-cnt"><a :href="`/detail/${aitem?.id}`"
                                                        :title="aitem?.title" class="ellipsis-2">{{ aitem?.title }}</a>
                                                </p>
                                            </div>
                                        </div>
                                    </div>

                                </div>
                            </div>
                        </div>
                    </template>

                </div>
            </main>
            <footer class="footer">
                <p><a style="text-decoration: none;color: #aaa;" href="/articles/769.html">Imprint</a> |
                    <a style="text-decoration: none;color: #aaa;" href="/articles/768.html">Privacy Policy</a> |
                    <a style="text-decoration: none;color: #aaa;" href="/articles/767.html">Terms of Service</a> |
                    <a style="text-decoration: none;color: #aaa;" href="/articles/770.html">Contact Us</a>
                </p>
                <p style="margin-top: 12px;">© 2024 - 2025 OhWellMind All Rights Reserved.</p>
            </footer>
        </div>


    </div>
</template>

<script setup lang="ts">
import { defineComponent, onMounted, ref } from 'vue'
defineComponent({ name: 'Home' })
import { ElMessage, ElMessageBox } from 'element-plus';
import { useRouter } from 'vue-router'
import { getHomePageData, getAllCategory } from '../api/api';
const router = useRouter()
const searchText = ref<string>('')
const data = ref([])
const category = ref([])

const showFeedBack = () => {
    ElMessageBox.prompt('Please input your feedback', 'Feedback', {
        confirmButtonText: 'OK',
        cancelButtonText: 'Cancel',
    })
        .then(() => {
            ElMessage({
                type: 'success',
                message: `THANK YOU`,
            })
        })
        .catch(() => {
            ElMessage({
                type: 'info',
                message: 'Input canceled',
            })
        })
}

const handleSearch = () => {
    if (!searchText.value) return
    router.push({
        name: 'SearchPage',
        query: { search: searchText.value }
    })
}

const goHome = () => {
    router.push('/')
}

const goArticle = (item) => {
    router.push({
        name: 'Article',
        params: { id: item?.id },
        query: { title: item.alias }
    })
}

const getData = () => {
    getHomePageData({ pageNum: 1, pageSize: 10, tagIdList: [1, 2, 4] })
        .then(response => {
            data.value = response.data
        })
        .catch(error => {
            console.error('Error fetching data:', error);
        });
}

const getCategory = () => {
    getAllCategory()
        .then(response => {
            category.value = response.data?.filter((item) => item.id === 108 || item.id === 111 || item.id === 112 || item.id === 113 || item.id === 120 || item.id === 121)
        })
        .catch(error => {
            console.error('Error fetching data:', error);
        });
}

onMounted(() => {
    getData()
    getCategory()
    document.body.style.backgroundColor = '#000'
})


</script>

<style lang="scss">
.home-layout {
    background-color: #000;
    min-height: 100vh;

    .home-main {
        max-width: 1680px;
        margin: auto;

        .header {
            margin-left: 90px;
            height: 100px;
            display: flex;
            justify-content: space-around;
            align-items: center;
            padding: 24px 20px;
            text-align: center;
            color: #fff;

            .pc-header-extra {
                display: flex;
                align-items: center;

                .pc-header-extra-item {
                    margin-right: 20px;
                }

                .pc-header-extra-item .dropdown-list {
                    min-width: 120px;
                }

                .pc-header-extra-item .dropdown-list-item {
                    text-transform: capitalize;
                }

                .dropdown {
                    position: relative;
                    cursor: pointer;

                    .dropdown-list {
                        overflow: hidden;
                        position: absolute;
                        display: none;
                        width: 100%;
                        height: 0;
                        left: -16px;
                        z-index: 999;
                        padding-top: 10px;
                        color: #fff;
                        background: transparent;
                        transition: height 1s;
                        border-radius: 0 0 8px 8px;

                        .dropdown-list-item {
                            padding: 12px;
                            text-align: center;
                            font-size: 16px;
                            line-height: 16px;
                            cursor: pointer;
                            background-color: rgba(128, 128, 128, 0.6);
                        }

                        .dropdown-list-item:hover {
                            background-color: #246def;
                        }

                        .dropdown-list-item:first-child {
                            border-radius: 8px 8px 0 0;
                        }
                    }
                }

                .dropdown:hover .dropdown-list {
                    display: block;
                    height: auto;
                }
            }

            @media screen and (max-width: 765px) {
                .pc-header-extra {
                    display: none;
                }
            }

            .pc-feedback {
                cursor: pointer;
            }
        }

        @media screen and (max-width: 765px) {
            .header {
                margin-left: 0;
                justify-content: center;
            }
        }

    }

    .main {
        max-width: 1200px;
        min-height: calc(100vh - 220px);
        margin: 0 auto;
        padding: 0 20px;

        .home-page {
            .trending-module {
                padding-bottom: 48px;
            }

            .home-page-module-title {
                position: relative;
                display: none;
                margin: 0 0 11px;
                padding-left: 4px;
                color: #fff;
                font-weight: 700;
                text-align: left;
                font-size: 20px;
                line-height: 24px;
            }

            .news-card {
                overflow: hidden;
                border-radius: 10px;
                transition: all .3s;
            }

            .vertical-news-card .news-card-top {
                overflow: hidden;
                cursor: pointer;
                opacity: 1;
                font-size: 0;
                transition: opacity .3s;
            }

            .news-card-dark a {
                color: #fff;
                text-decoration: none;

            }

            .news-card-cnt {
                margin-top: 5px;
            }

            .news-card-img-link {
                display: block;
            }

            .news-card-dark.vertical-news-card img {
                border-radius: 10px;
            }

            .vertical-news-card img {
                width: 100%;
                height: 220px;
            }

            .trend-list {
                display: flex;
                flex-wrap: wrap;

            }

            .news-card-dark.vertical-news-card img {
                border-radius: 10px;
            }

            .recent-publish-module-list {
                display: flex;
                flex-wrap: wrap;
                gap: 10px;
                padding-bottom: 50px;

                .recent-publish-module-list-right {
                    display: flex;
                    flex-wrap: wrap;
                    gap: 10px;
                    width: 50%;
                    height: 100%;


                }
            }

            .recent-publish-module-list-item {
                width: calc(45%);
                margin-right: 20px;
            }

            .recent-publish-module-list-item-img-large img {
                min-height: 340px !important;
            }




            @media screen and (min-width: 765px) {
                .trend-list-item {
                    width: calc(30% + 5.22px);
                    margin-bottom: 18px;
                    margin-right: 20px;
                }
            }

            @media screen and (min-width: 600px) and (max-width: 800px) {
                .trend-list-item {
                    width: calc(46%);
                    margin-bottom: 18px;
                    margin-right: 20px;
                }
            }

            @media screen and (max-width: 600px) {
                .trend-list-item {
                    width: 100%;
                    margin-bottom: 16px;
                }
            }

            @media screen and (min-width: 765px) {
                .home-page-module-title {
                    margin-bottom: 19px;
                    font-size: 28px;
                    line-height: 33px;
                }
            }

            @media screen and (min-width: 765px) {
                .home-page-module-title {
                    display: block;
                }
            }

            @media screen and (min-width: 765px) {
                .home-page-module-title {
                    display: block;
                }
            }

            @media screen and (max-width: 800px) {
                .recent-publish-module {
                    display: none;
                }
            }

            @media screen and (max-width: 1000px) {
                .recent-publish-module-list-item {
                    width: 43%;
                }
            }
        }

        .search-bar-dark {
            background-color: #334155;
            border: 1px solid hsla(0, 0%, 100%, .4);
        }

        .search-bar-wrap {
            display: flex;
            align-items: center;
            width: calc(100% - 6px);
            max-width: 748px;
            height: 44px;
            padding: 9px 12px;
            margin: 40px auto 30px;
            border-radius: 10px;
        }

        .adm-input {
            --font-size: var(--adm-font-size-9);
            --color: var(--adm-color-text);
            --placeholder-color: var(--adm-color-light);
            --text-align: left;
            --background-color: transparent;
            display: flex;
            justify-content: flex-start;
            align-items: center;
            width: 100%;
            max-width: 100%;
            max-height: 100%;
            min-height: 24px;
            background-color: var(--background-color);
        }

        .search-bar-input {
            width: calc(100% - 40px);
            height: 30px;
            line-height: 30px;
            font-size: 16px;
            border: none;


        }

        .search-bar-dark .adm-input-element {
            color: #fff;
        }

        .search-bar-input .adm-input-element {
            font-style: italic;
        }

        .adm-input-element {
            flex: auto;
            display: inline-block;
            box-sizing: border-box;
            width: 100%;
            max-width: 100%;
            max-height: 100%;
            padding: 0;
            margin: 0;
            color: var(--color);
            font-size: var(--font-size);
            line-height: 1.5;
            background: transparent;
            border: 0;
            outline: none;
            -webkit-appearance: none;
            appearance: none;
            min-height: 1.5em;
            text-align: var(--text-align);
        }

        .search-icon {
            width: 18px;
            height: 18px;
            margin-left: 6px;
            background: no-repeat url(https://6gamehub.com/static/img/bestreplyai/search-icon.webp);
            background-size: 18px 18px;
            cursor: pointer;
        }


        .all-article-module {
            padding-bottom: 50px !important;



        }

        .all-article-module-list {
            display: flex;
            flex-wrap: wrap;

            .all-article-module-list-item-large {
                padding-right: 20px;
            }

            .all-article-module-list-item {
                width: 46.3%;
                margin-bottom: 11px;
            }

            .all-article-module-list-right {
                flex: 1 1;
                flex-direction: column;
                display: flex;
            }

            .all-article-module-list-item-right {
                margin-bottom: 15px;
            }

            .horizontal-news-card {
                display: flex;

                .news-card-right {
                    flex: 0.9 1;
                    padding: 0 10px;
                }

                .news-card-img-link {
                    display: block;
                }
            }

            .horizontal-news-card img {
                width: 285px;
                height: 160px;
            }

        }

        @media screen and (max-width: 800px) {
            .all-article-module {
                display: none;
            }
        }
    }

    @media screen and (min-width: 765px) {
        .main {
            min-width: 500px;
        }
    }


    .footer {
        color: #aaa;
        margin: 0 auto;
        padding: 20px 0;
        font-size: 14px;
        line-height: 13px;
        text-align: center;
    }


}
</style>